<?
require_once("pg_mon/class_SchemaName.php");

class WUSchemaName extends SchemaName {

    public function __construct($sn_id=false) {
	parent::__construct($sn_id);
    }

    public function update_schema($changes) {
	$old=$this->get_all_fields();
	if ($old['description'] != $changes['edit_sn__description']) {
	    $this->set_field('description',$changes['edit_sn__description']);
	}
	if ($old['observable'] != $changes['edit_sn__observable']) {
	    $this->set_field('observable',$changes['edit_sn__observable']);
	}
	$this->save();
    }

    public function get_view() {
	$string="
<table border=0 align=center width=70%>
    <tr align=center valign=top>
	<td align=left>
	    <a href=".$_SERVER['PHP_SELF']."?level=schema&action=discover&id=".$this->id.">Discover</a><br><br>
	    <form method=POST action=".$_SERVER['PHP_SELF'].">
<input type=hidden name=level value=schema>
<input type=hidden name=id value=".$this->get_id().">
<select name=edit_sn__observable>";
	foreach (array('Observable'=>'t','Suspended'=>'f') as $name=>$val) {
	    $string.="<option value=".$val;
	    if ($val == $this->get_field('observable')) {
		$string.=" selected";
	    }
	    $string.=">".$name."</option>";
	}
	$string.="</select><br><br>
	</td><td>
	<table border=0>
	    <tr>
		<td>Schema OID</td>
		<td><b>".$this->get_field('obj_oid')."</b></td>
	    </tr><tr valign=top>
		<td>Description</td>
		<td><textarea wrap name=edit_sn__description rows=7 cols=45>".($this->get_field('spec_comments') ? $this->get_field('spec_comments') : '')."</textarea></td>
	    </tr>
	</table><hr width=70%><br><input type=submit name=edit_sn__submit value=Save>&nbsp<input type=reset value=Reset></form>";
	return $string;
    }




    public function print_config_table_row($added) {
	if (!$this->loaded) {
	    $this->load();
	}
	$rowspan=$this->composit_array['table_name']['collection']->get_item_count()+1;
	if (in_array($this->database_fields['sch_name'],$added)) {
	    $string= "<tr valign=top bgcolor=#DDD>";
	} else {
	    $string="<tr valign=top>";
	}
	
	$string.="<td rowspan=".$rowspan." bgcolor=#CCC><b>".$this->database_fields['sch_name']."</b></td>
	    <td rowspan=".$rowspan.">".$this->database_fields['description']."</td>
	    <td rowspan=".$rowspan." align=center>".($this->database_fields['observable'] == 't' ? 'Yes' : '<i>No</i>')."</td>
	    <td rowspan=".$rowspan."><a href=".$_SERVER['PHP_SELF']."?action=edit&content=schema_name&sn_id=".$this->id."><i>Edit</i></a></td>
	    <td>&nbsp;</td>";
	$string.="</tr>";
	foreach ($this->composit_array['table_name']['collection']->get_object_array() as $tn) {
	    $string.="<tr><td bgcolor=#EEE valign=top>".$tn."</td><td><table width=100% border=0>";
	    foreach ($tn->get_composit_array() as $in) {
		$string.=$in->print_config_table_row();
	    }
	    $string.="</table></tr>";
	}
	$string.="<tr><td colspan=6><hr width=80%></td></tr>";
	return $string;
    }

    public function __toString() {
	return $this->get_field('sch_name');
    }
}

?>
